#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/16 16:25
# @Author: 徐洪英
# @Email: xx@gmail.com
# @File：add_rie_list_page.py
from selenium.webdriver.common.by import By
from config.config import HOST
from time import sleep
from pages.base_page import BasePage
class AddRieListPage(BasePage):
    """类属性"""
    url="http://{}/crm/index.php?m=finance&a=add&t=receivingorder".format(HOST)
    receivables_locator = (By.ID, "receivables")  # 应收款
    field_ys_locator = (By.XPATH, "/html/body/div[7]/div[2]/table/tbody[2]/tr[1]/td[1]/input")  # 选择应收款徐大大
    ui_button_locator = (By.XPATH, "/html/body/div[7]/div[3]/div/button[1]")  # 点击ok
    money_locator = (By.ID, "money")  # 收款金额
    pay_time_locator = (By.ID, "pay_time")  # 收款时间
    status_locator = (By.NAME, "status")  # 选择未结账
    yi_status_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]/input[2]")  # 选择已结账
    description_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[8]/td[2]/textarea")  # 描述
    submit_locator = (By.NAME, "submit")  # 保存
    cat_locator = (By.XPATH, "/html/body/div[5]/div[3]/div[2]/table/tbody/tr[1]/td[9]/a[1]")  # 查看收款单
    return_rie_list_locator=(By.LINK_TEXT,"返回")#返回
    choose_rie_all_list_locator=(By.ID,"check_all")#全部选中
    choose_rie_list_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > table > tbody > tr:nth-child(2) > td:nth-child(1) > input")#选中单个
    delete_locator = (By.XPATH, "/html/body/div[5]/div[3]/div[1]/div[1]/a")  #点击 删除
    add_rie_list_locator = (By.XPATH, "/html/body/div[5]/div[2]")  # 断言添加成功
    delete_rie_list_locator = (By.XPATH, "/html/body/div[5]/div[2]")  # 断言删除成功
    time_add_success_locator = (By.XPATH, "/html/body/div[5]/div[2]")  # 断言添加成功时间
    save_add_locator=(By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tfoot > tr > '
                                      'td:nth-child(2) > input:nth-child(2)')#保存并新建
    def receivables(self):
        """点击应收款"""
        self.driver.find_element(*self.receivables_locator).click()
        sleep(2)
    def field_ys(self):
        """查找应收款"""
        self.driver.find_element(*self.field_ys_locator).click()  # 查找应收款单元素
        sleep(2)
    def ui_button(self):
        """点击ok"""
        self.driver.find_element(*self.ui_button_locator).click()  # 查找ok元素，并点击
    def money_input(self,money):
        """输入收款单金额"""
        self.driver.find_element(*self.money_locator).send_keys(money)  # 查找收款金额元素，并输入内容
    def pay_time_input(self,pay_time):
        """输入收款时间"""
        pay_time_element = self.driver.find_element(*self.pay_time_locator)
        pay_time_element.clear()
        pay_time_element.send_keys(pay_time)
    def no_status(self):
        """选择未结账"""
        self.driver.find_element(*self.status_locator).click()#选择未结账元素，并点击
    def yi_status(self):
        """选择已结账"""
        self.driver.find_element(*self.yi_status_locator).click()  # 选择已结账元素，并点击
    def description_list(self,description):
        """输入描述内容"""
        self.driver.find_element(*self.description_locator).send_keys(description)  # 查找描述,并输入内容
    def rie_submit_list(self):
        """点击保存"""
        self.driver.find_element(*self.submit_locator).click()  # 查找保存元素，并点击按钮
    def sava_add_list(self):
        """点击保存并新建"""
        self.driver.find_element(*self.save_add_locator).click()

    def rie_cat_list(self):
        """查看收款单"""
        self.driver.find_element(*self.cat_locator).click()
    def click_return(self):
        """点击返回"""
        self.driver.find_element(*self.return_rie_list_locator).click()
    def choose_all_rie_click(self):
        """选中全部的应该收单"""
        self.driver.find_element(*self.choose_rie_all_list_locator).click()
    def choose_rie_list_click(self):
        """选中单个"""
        self.driver.find_element(*self.choose_rie_list_locator).click()

    def click_delete_rie(self):
        """点击删除"""
        self.driver.find_element(*self.delete_locator).click()

    def accept_list_delete(self):
        """确认删除弹框"""
        self.driver.switch_to.alert.accept()  # 弹框确认

    def actual_add_rie_list_stutas(self):
        """断言添加应款单"""
        actual = self.driver.find_element(*self.add_rie_list_locator).text
        return actual
    def actual_return_rie_list_stutas(self):
        """断言查看并返回添加页面"""
        actual = self.driver.current_url
        return actual

    def actual_delete_all_rie_list_stutas(self):
        """断言删除全部的收款单"""
        actual = self.driver.find_element(*self.delete_rie_list_locator).text
        return actual

    def actual_time_stutas(self):
        """断言添加应收款"""
        actual = self.driver.find_element(*self.time_add_success_locator).text
        return actual